<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="nav" content="0" />
<meta name="acc" content="1-0-0" />
<title>发文登记</title>
<style type="text/css">
.pop_box {
	background-color: #cccccc;
	display: none;
	padding: 5px;
	position: fixed;
	width: 100%;
	height: 100%;
	z-index: 9999;
}
</style>
<script src="${ctx}/scripts/jqmodal/jqModal.js" type="text/javascript"></script>
<link href="${ctx}/styles/jqmodal/jqModal.css" rel="stylesheet" />
<script type="text/javascript"
	src="<c:url value='/ext/ui/jquery-ui-1.8.12.custom.min.js'/>"></script>
<link href="${ctx}/styles/lightness/jquery-ui-1.8.12.custom.css"
	rel="stylesheet" />
<%@ include file="/common/extjs.jsp"%>
<script type="text/javascript" charset="utf-8"
	src="<c:url value='/KindEditor/kindeditor.js'/>"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$("#title").focus();
						var $validate1 = $("#inputForm")
								.validate(
										{
											event : "blur",
											rules : {
												title : {
													required : true,
													maxlength : 50,
													remote : "${ctx}/admin/convey!checkTitle.action?oldTitle="
															+ encodeURIComponent('${title}')
												},
												num : {
													required : true,
													maxlength : 50,
													remote : "${ctx}/admin/convey!checkNum.action?oldNum="
															+ encodeURIComponent('${num}')
												},
												type : "required",
												secret : "required",
												crash : "required",
												takeOrgName : "required",
												source : "required"
											},
											messages : {
												title : {
													remote : "<font color='red'>发文标题已存在</font>"
												},
												num : {
													remote : "<font color='red'>发文字号已存在</font>"
												}
											}
										});
						var $testDialog = $("#pop").dialog({
							title : "资料上传",
							autoOpen : false,
							modal : true
						});
						$("#process")
								.click(
										function() {
											$("#inputForm")
													.attr("action",
															"${ctx}/admin/convey!second.action");
											KE.sync("content");
											$("#inputForm").submit();
											if ($validate1.numberOfInvalids()) {
											} else {
												$testDialog.dialog('open');
											}
										});

						$("#a_save")
								.click(
										function() {
											$("#inputForm")
													.attr("action",
															"${ctx}/admin/convey!save2.action");
											KE.sync("content");
											$("#inputForm").submit();
											if ($validate1.numberOfInvalids()) {
											} else {
												$testDialog.dialog('open');
											}
										});
						$("#b_save").click(function() {
							KE.sync("content");
							$("#inputForm").submit();
							if ($validate1.numberOfInvalids()) {
							} else {
								$testDialog.dialog('open');
							}
						});

						$("#name").click(function() {
							UserNameSelector.getView(function(a, c) {
								$("#name").val(c);
								$("#username").val(a);
								if (a != "") {
									var count = a.split(",").length;
									$("#value").val(count);
								}
							}).show();
						});
						$("#usern").click(function() {
							UserSelector.getView(function(a, c) {
								$("#usern").val(c);
								$("#userid").val(a);
							}, true).show();
						});
					});

	KE.show({
		id : 'content',
		cssPath : './index.css',
		afterCreate : function(id) {
			KE.event.ctrl(document, 13, function() {
				KE.sync(id);
				document.forms['inputForm'].submit();
			});
			KE.event.ctrl(KE.g[id].iframeDoc, 13, function() {
				KE.sync(id);
				document.forms['inputForm'].submit();
			});
		}
	});

	var i = 1;
	function addFile(divName, fileName) {
		var dv = document.getElementById(divName);

		var file = document.createElement("input");
		file.type = "file";
		file.name = fileName;
		file.id = fileName + i;
		dv.appendChild(file);

		var btn = document.createElement("input");
		btn.type = "button";
		btn.id = btn.name = "btn" + i;
		btn.value = "删除";

		btn.onclick = function() {
			var b = document.getElementById(btn.id);
			dv.removeChild(b.nextSibling);
			dv.removeChild(b.previousSibling);
			dv.removeChild(b);
		}
		dv.appendChild(btn);
		dv.appendChild(document.createElement("BR"));

		i++;
	}

	function clo() {
		var id = $("input[name='id']").val();
		$(window.parent.conveyReach(id));
		$(window.parent.close());
	}
</script>
</head>
<body>
	<div class="pop_box" id="pop">
		<h4>正在上传资料，请耐心等待...</h4>
	</div>
	<br>
	<form action="${ctx }/admin/convey!save.action" method="post"
		id="inputForm" class="yform" enctype="multipart/form-data"
		target="_parent">
		<div id="caption">
			<h6>${licenseplateNumber}发文登记</h6>
		</div>
		<input type="hidden" name="id" id="id" value="${id }"> <input
			type="hidden" name="taskId" id="taskId" value="${taskId }">
		<table class="noborder">
			<tr class="type-text">
				<td>发文标题</td>
				<td colspan="3"><input type="text" name="title"
					value="${title }" /></td>
			</tr>
			<tr class="type-text">
				<td>发文字号</td>
				<td colspan="3"><c:if test="${not empty num }">
						${num}
					</c:if> <c:if test="${empty num }">
						东交监<pt:code category="1019" name="letter" width="100"></pt:code>(注:[]中的数和随机数由后台自动产生)
					</c:if></td>
			</tr>
			<tr>
				<td>公文类型</td>
				<td><input type="text" name="type" id="type" value="${type }">
				</td>
				<td>份数</td>
				<td><input type="text" name="source" id="source"
					value="${source }"></td>
			</tr>
			<tr class="type-text">
				<td>紧急程度</td>
				<td><pt:code category="3053" name="crash" default="${crash }"></pt:code>
				</td>
				<td>密集程度</td>
				<td><pt:code category="3054" name="secret" default="${secret }"></pt:code>
				</td>
			</tr>
			<tr class="type-text">
				<td>主送单位</td>
				<td colspan="3"><input type="text" name="takeOrgName"
					value="${takeOrgName }" /></td>
			</tr>
			<tr class="type-text">
				<td>抄送单位</td>
				<td colspan="3"><input type="text" name="copyOrgName"
					value="${copyOrgName }" /></td>
			</tr>
			<tr class="type-text">
				<td>主题词</td>
				<td colspan="3"><input type="text" name="keywords"
					value="${keywords }" /></td>
			</tr>
			<tr class="type-text">
				<td>内容简介</td>
				<td colspan="3"><textarea name="content" id="content">${content }</textarea>
				</td>
			</tr>
			<tr class="type-text">
				<td>备注</td>
				<td colspan="3"><textarea id="remark" name="remark">${remark }</textarea>
				</td>
			</tr>
			<tr class="type-text">
				<td><input type="button" value="添加上传"
					onclick="addFile('sources','upload')" /></td>
				<td colspan="3" id="sources"></td>
			</tr>
		</table>
		<c:if test="${not empty attachmentSet }">
			<div id="caption">
				<h6>${licenseplateNumber}已有附件</h6>
			</div>
			<table>
				<c:forEach items="${attachmentSet }" var="attachment"
					varStatus="state">
					<tr id="tr${state.index }">
						<td colspan="4"><a title="下载"
							href="${ctx}/servlet/annex?id=${attachment.id}">${attachment.upfileFileName}(${attachment.type})<fmt:formatDate
									value="${attachment.fileTime}" pattern="yyyy-MM-dd" />
						</a> <span
							onclick="deleteAttachmentById('${attachment.id}','tr${state.index }')"
							class="delete" title="删除附件"></span></td>
					</tr>
				</c:forEach>
			</table>
		</c:if>
		<div class="type-button">
			<c:if test="${empty cFlag }">
				<input type="button" id="b_save" name="b_save" value="暂存"
					class="submit">
			</c:if>
			<c:if test="${not empty cFlag }">
				<input type="button" name="a_save" id="a_save" value="保存"
					class="submit">
			</c:if>
			<c:if test="${status == '01' || status == null }">
				<input class="button" type="button" id="process" value="提交" />&nbsp;
			</c:if>
			<c:if test="${empty cFlag }">
				<input class="reset" type="button" value="返回" class="rest"
					onclick="history.back()" />
			</c:if>
			<c:if test="${not empty cFlag }">
				<input type="button" class="button" value="关闭"
					onclick="javascript:clo();">
			</c:if>
		</div>
	</form>
</body>
</html>